Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / the jucer / src / ui / jucer_TestComponent.cpp
blob9b4e622e0ca5702c7fcc52cad720375cb82f9d7a
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../jucer_Headers.h"
27 #include "jucer_TestComponent.h"
28 #include "../model/jucer_ObjectTypes.h"
31 static Array <TestComponent*> testComponents;
33 //==============================================================================
34 TestComponent::TestComponent (JucerDocument* const ownerDocument_,
35 JucerDocument* const loadedDocument_,
36 const bool alwaysFillBackground_)
37 : ownerDocument (ownerDocument_),
38 loadedDocument (loadedDocument_),
39 alwaysFillBackground (alwaysFillBackground_)
41 setToInitialSize();
42 updateContents();
43 testComponents.add (this);
46 TestComponent::~TestComponent()
48 testComponents.removeValue (this);
49 deleteAllChildren();
50 delete loadedDocument;
53 //==============================================================================
54 void TestComponent::reloadAll()
56 for (int i = testComponents.size(); --i >= 0;)
57 testComponents.getUnchecked(i)->reload();
60 void TestComponent::reload()
62 if (findFile().exists() && lastModificationTime != findFile().getLastModificationTime())
63 setFilename (filename);
66 //==============================================================================
67 static StringArray recursiveFiles;
69 const File TestComponent::findFile() const
71 if (filename.isEmpty())
72 return File::nonexistent;
74 if (ownerDocument != 0)
75 return ownerDocument->getFile().getSiblingFile (filename);
77 return File::getCurrentWorkingDirectory().getChildFile (filename);
80 void TestComponent::setFilename (const String& newName)
82 File newFile;
84 if (newName.isNotEmpty())
86 if (ownerDocument != 0)
87 newFile = ownerDocument->getFile().getSiblingFile (newName);
88 else
89 newFile = File::getCurrentWorkingDirectory().getChildFile (newName);
92 if (! recursiveFiles.contains (newFile.getFullPathName()))
94 recursiveFiles.add (newFile.getFullPathName());
96 deleteAndZero (loadedDocument);
98 filename = newName;
99 lastModificationTime = findFile().getLastModificationTime();
101 loadedDocument = ObjectTypes::loadDocumentFromFile (findFile(), false);
103 updateContents();
104 repaint();
106 recursiveFiles.remove (recursiveFiles.size() - 1);
110 void TestComponent::setConstructorParams (const String& newParams)
112 constructorParams = newParams;
115 void TestComponent::updateContents()
117 deleteAllChildren();
118 repaint();
120 if (loadedDocument != 0)
122 addAndMakeVisible (loadedDocument->createTestComponent (alwaysFillBackground));
123 resized();
127 void TestComponent::setToInitialSize()
129 if (loadedDocument != 0)
131 setSize (loadedDocument->getInitialWidth(),
132 loadedDocument->getInitialHeight());
134 else
136 setSize (100, 100);
140 //==============================================================================
141 void TestComponent::paint (Graphics& g)
143 if (loadedDocument == 0)
145 g.fillAll (Colours::white.withAlpha (0.25f));
147 g.setColour (Colours::black.withAlpha (0.5f));
148 g.drawRect (0, 0, getWidth(), getHeight());
149 g.drawLine (0.0f, 0.0f, (float) getWidth(), (float) getHeight());
150 g.drawLine (0.0f, (float) getHeight(), (float) getWidth(), 0.0f);
152 g.setFont (14.0f);
153 g.drawText ("Jucer Component",
154 0, 0, getWidth(), getHeight() / 2,
155 Justification::centred, true);
156 g.drawText ("(no file loaded)",
157 0, getHeight() / 2, getWidth(), getHeight() / 2,
158 Justification::centred, true);
162 void TestComponent::resized()
164 Component* const c = getChildComponent (0);
166 if (c != 0)
168 setOpaque (c->isOpaque());
169 c->setBounds (0, 0, getWidth(), getHeight());
173 //==============================================================================
174 void TestComponent::showInDialogBox (JucerDocument& document)
176 TooltipWindow tooltipWindow (0, 400);
178 TestComponent testComp (0, document.createCopy(), true);
180 DialogWindow::showModalDialog ("Testing: " + document.getClassName(),
181 &testComp, 0,
182 Colours::azure,
183 true, true);